<template>
  <el-dialog  v-model="visible" :title="!dataForm.id ? '新增' : '修改'" :close-on-click-modal="false" :close-on-press-escape="false">
    <el-form :model="dataForm" :rules="rules" ref="dataFormRef" @keyup.enter="dataFormSubmitHandle()" label-width="120px">
      <el-form-item label="选择员工" prop="userId">
        <el-select class="w100" @change="jxcrtxr" v-model="dataForm.userId" placeholder="请选择员工" clearable filterable>
          <el-option v-for="item in xczxtrt"
           :key="item.id" :label="item.realName"
            :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>
          <!-- <el-form-item label="1 申请住宿 2 宿舍报修 3 申请退宿 4 离职报备 5 意见反馈 6 合同管理 7 抽奖活动  99 个人资料应聘  
对应字典user_data_type" prop="type">
        <el-input v-model="dataForm.type" placeholder="1 申请住宿 2 宿舍报修 3 申请退宿 4 离职报备 5 意见反馈 6 合同管理 7 抽奖活动  99 个人资料应聘  
对应字典user_data_type"></el-input>
      </el-form-item> -->
          <!-- <el-form-item label="反馈类型 字典编码 " prop="contentDicCode">
        <el-input v-model="dataForm.contentDicCode" placeholder="反馈类型 字典编码 "></el-input>
      </el-form-item> -->
          <!-- <el-form-item label="反馈类型" prop="contentType">
        <el-input v-model="dataForm.contentType" placeholder="反馈类型"></el-input>
      </el-form-item> -->
          <el-form-item label="合同名称   " prop="content">
        <el-input v-model="dataForm.content" placeholder="内容   "></el-input>
      </el-form-item>
          <!-- <el-form-item label="资料id" prop="imgId">
        <el-input v-model="dataForm.imgId" placeholder="资料id"></el-input>
      </el-form-item> -->
          <el-form-item label="上传的资料" prop="imgUrl">
           
            <div class="w100" v-if="dataForm.imgUrl">
              <dimgduoge :dximg="dataForm.imgUrl" @getimg="xzczxtrtbanner"></dimgduoge>
            </div>
            <div class="w100" v-else>
              <dimgduoge :dximg="dataForm.imgUrl" @getimg="xzczxtrtbanner"></dimgduoge>
            </div>
<!-- 

        <el-input v-model="dataForm.imgUrl" placeholder="上传的资料"></el-input> -->
      </el-form-item>
          <!-- <el-form-item label="排序" prop="sort">
        <el-input v-model="dataForm.sort" placeholder="排序"></el-input>
      </el-form-item> -->
          <!-- <el-form-item label="1 待审核 2审核通过 3审核不通过" prop="isPass">
        <el-input v-model="dataForm.isPass" placeholder="1 待审核 2审核通过 3审核不通过"></el-input>
      </el-form-item> -->
          <!-- <el-form-item label="审核不通过内容" prop="passContent">
        <el-input v-model="dataForm.passContent" placeholder="审核不通过内容"></el-input>
      </el-form-item> -->
          <!-- <el-form-item label="创建时间" prop="createTime">
        <el-input v-model="dataForm.createTime" placeholder="创建时间"></el-input>
      </el-form-item>
          <el-form-item label="更新时间" prop="updateTime">
        <el-input v-model="dataForm.updateTime" placeholder="更新时间"></el-input>
      </el-form-item> -->
          <!-- <el-form-item label="企业id" prop="companyId">
        <el-input v-model="dataForm.companyId" placeholder="企业id"></el-input>
      </el-form-item>
          <el-form-item label="归属企业" prop="companyName">
        <el-input v-model="dataForm.companyName" placeholder="归属企业"></el-input>
      </el-form-item>
          <el-form-item label="真实姓名" prop="realName">
        <el-input v-model="dataForm.realName" placeholder="真实姓名"></el-input>
      </el-form-item>
          <el-form-item label="联系电话" prop="userPhone">
        <el-input v-model="dataForm.userPhone" placeholder="联系电话"></el-input>
      </el-form-item> -->
      </el-form>
    <template #footer>
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmitHandle()">确定</el-button>
    </template>
  </el-dialog>
</template>

<script lang="ts" setup>
import { reactive, ref } from "vue";
import baseService from "@/service/baseService";
import { ElMessage } from "element-plus";
import { dxget } from "@/utils/utils";
const emit = defineEmits(["refreshDataList"]);
import dimgduoge  from "@/components/dimgduoge.vue";
const xczxtrt = ref([])
const visible = ref(false);
const dataFormRef = ref();

const dataForm = reactive({
  id: '',  userId: '',  type: '',  contentDicCode: '',  contentType: '',  content: '',  imgId: '',  imgUrl: '',  sort: '',  isPass: '',  passContent: '',  createTime: '',  updateTime: '',  companyId: '',  companyName: '',  realName: '',  userPhone: ''});

const rules = ref({
          userId: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          type: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          contentDicCode: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          contentType: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          content: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          imgId: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          imgUrl: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          sort: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          isPass: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          passContent: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          createTime: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          updateTime: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          companyId: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          companyName: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          realName: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          userPhone: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ]
  });

const init = (id?: number) => {
  visible.value = true;
  dataForm.id = "";
  dataForm.contentType = 6
  dataForm.imgUrl = ""
  // 重置表单数据
  if (dataFormRef.value) {
    dataFormRef.value.resetFields();
  }

  if (id) {
    getInfo(id);
  }
};

// 获取信息
const getInfo = (id: number) => {
  baseService.get("/api/userdata/" + id).then((res) => {
    Object.assign(dataForm, res.data);
  });
};

// 表单提交
const dataFormSubmitHandle = () => {
  dataFormRef.value.validate((valid: boolean) => {
    if (!valid) {
      return false;
    }
    (!dataForm.id ? baseService.post : baseService.put)("/api/userdata", dataForm).then((res) => {
      ElMessage.success({
        message: '成功',
        duration: 500,
        onClose: () => {
          visible.value = false;
          emit("refreshDataList");
        }
      });
    });
  });
};

defineExpose({
  init
});
const jmkxcf = async () => {

const { list } = await dxget('/api/user/page', {
  limit: 999,
  isAuthentication:true
})
xczxtrt.value = list
}
jmkxcf()

const xzczxtrtbanner = (data)=>{
  const kcvds = []
  data.map(a=>{
    kcvds.push(a.url)
  })
  dataForm.imgUrl = kcvds.join(",")
}
</script>
